<script setup lang="ts">
/**
 * @desc ExpressionNode
 * @author MiyueFE <https://github.com/miyuesc>
 * @since 2024/7/12 上午10:07
 */

import type { PropType } from 'vue'
import { computed } from 'vue'
import { Variable } from 'lucide-vue-next'
import type { ExpressionNode, FlowDirection } from '@/types'
import { checkDefaultExpressionFlow, checkParallelGateway } from '@/configuration/check-node-types'

defineOptions({ name: 'ExpressionNode' })

const $props = defineProps({
  data: {
    type: Object as PropType<ExpressionNode>,
    required: true,
  },
  direction: {
    type: String as PropType<FlowDirection>,
    default: 'vertical',
    validator: (v: FlowDirection) => ['vertical', 'horizontal'].includes(v),
  },
})
defineEmits(['update:data'])

const isParallelGatewayChild = computed(() => checkParallelGateway($props.data))
const isDefaultFlow = computed(() => checkDefaultExpressionFlow($props.data))
</script>

<template>
  <div
    class="flow-node flow-expression"
  >
    <div class="flow-node_header">
      <Variable :size="16" /><span>{{ data.name }}</span>
    </div>
    <div class="flow-node_content">
      <div v-if="isParallelGatewayChild">
        并行执行，无需条件
      </div>
      <div v-else>
        {{ isDefaultFlow ? '默认条件' : (data.expression || '未配置条件') }}
      </div>
    </div>
  </div>
</template>
